import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
 
public class NetworkBandwidth {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int cc = 1;
        int nodes = in.nextInt();
        while (nodes != 0) {
            int[][] network = new int[nodes + 1][nodes + 1];
            int s = 0, t = 0;
            int[] parent = new int[nodes + 1];
            int[] cost = new int[nodes + 1];
            s = in.nextInt();
            t = in.nextInt();
            int edges = in.nextInt();
            while (edges-- > 0) {
                int st = in.nextInt();
                int en = in.nextInt();
                int cst = in.nextInt();
                network[st][en] += cst;
                network[en][st] += cst;
            }
            cost[s] = Integer.MAX_VALUE;
            parent[s] = s;
            int maxflow = 0;
            boolean done = false;
            while (!done) {
                done = true;
                Queue<Integer> q = new LinkedList<Integer>();
                q.add(s);
                boolean[] vis = new boolean[network.length];
                vis[s] = true;
                while (!q.isEmpty()) {
                    int n = q.poll();
                    if (n == t) {
                        done = false;
                        break;
                    }
                    for (int i = 0; i < network.length; i++)
                        if (network[n][i] > 0 && !vis[i]) {
                            parent[i] = n;
                            cost[i] = Math.min(cost[n], network[n][i]);
                            vis[i] = true;
                            q.add(i);
                        }
                }
                if (!done) {
                    maxflow += cost[t];
                    int n = t;
                    while (parent[n] != n) {
                        network[parent[n]][n] -= cost[t];
                        network[n][parent[n]] += cost[t];
                        n = parent[n];
                    }
                }
            }
            System.out.printf("Network %d\n", cc++);
            System.out.printf("The bandwidth is %d.\n\n", maxflow);
            nodes = in.nextInt();
        }
    }
}